package com.huangliusong.desigin.pattern.creational.singleton;

import java.io.*;

/**
 * @author huangliusong
 * @since 2018/10/11
 * {@link }
 */
public class TestEnumInstance {
    public static void main(String[] args) throws IOException, ClassNotFoundException {
        EnumInstance instance=EnumInstance.getInstance();
        instance.setData(new Object());


        ObjectOutputStream oos=new ObjectOutputStream(new FileOutputStream("file"));
        oos.writeObject(instance);


        File file=new File("file");
        ObjectInputStream ois=new ObjectInputStream(new FileInputStream(file));

       // HungrySingleton newInstance=(HungrySingleton)ois.readObject();

        EnumInstance newInstance= (EnumInstance) ois.readObject();

        System.out.println(instance.getData());
        System.out.println(newInstance.getData());
        System.err.println(instance==newInstance);
    }
}
